// 润乾报表公共组件
import React from 'react';
import { $http } from 'containers/config/https';
import { httpConfig } from 'containers/config/httpConfig';
class reports extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            url: '',
        }
    }

    componentDidMount() {
        this.getRaqSoftPath();
    }

    //获取润乾服务器路径
    getRaqSoftPath = () => {
        $http.post('urlS', this, {
            code: "01040114",
            data: {
                params: [{ appCode: '' }]
            },
            success: function (res) {
                if (res.errorCode == 0) {
                    let raqName = '';
                    if (this.props.location) {
                        if (this.props.location.state.raqName) {
                            raqName = this.props.location.state.raqName ? this.props.location.state.raqName : "";
                        }
                    } else {
                        raqName = this.props.paras.raqName ? this.props.paras.raqName : "";
                    }
                    if (raqName.indexOf(".rpx") === -1) {
                        raqName = raqName + ".rpx";
                    }
                    let session = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
                    let sessionUserID = session.userID;
                    let sessionUserName = session.userName;
                    let sessionLocID = session.locID;
                    let sessionLocDesc = session.locDesc;
                    let sessionGroupID = session.groupID;
                    let sessionGroupDesc = session.groupDesc;
                    let sessionHospID = session.hospDesc;
                    let sessionHospDesc = session.hospDesc;
                    let sessionNowHospID = session.hospID;

                    /**
                     * @ByYQL: 报表链接新增病人入参 admID、patID
                     * Create 2022-3-4
                     */
                    let sessionPatientData = window.sessionStorage.patientData ? JSON.parse(window.sessionStorage.patientData) : {};
                    let _admID = sessionPatientData.admID || '';
                    let _patID = sessionPatientData.patID || '';

                    let sessionStr = "&sessionUserID=" + sessionUserID + "&sessionUserName=" + sessionUserName + "&sessionLocID=" + sessionLocID + "&sessionLocDesc=" + sessionLocDesc + "&sessionGroupID=" + sessionGroupID + "&sessionGroupDesc=" + sessionGroupDesc + "&sessionHospID=" + sessionHospID + "&sessionHospDesc=" + sessionHospDesc + "&sessionNowHospID=" + sessionNowHospID + "&sessionAdmID=" + _admID + "&sessionPatID=" + _patID;
                    let splitUrl = '';
                    if (res.result.path.indexOf("//") > -1) {
                        let newUrl = res.result.path.split("//")[1];
                        if (newUrl.indexOf("/") > -1) {
                            for (var i = 1; i < newUrl.split("/").length; i++) {
                                splitUrl = splitUrl + "/" + newUrl.split("/")[i];
                                // if(splitUrl===''){
                                //     splitUrl=newUrl.split("/")[i];
                                // }else{
                                //     splitUrl=splitUrl+"/"+newUrl.split("/")[i];
                                // }
                            }
                        } else {
                            splitUrl = "/" + newUrl;
                        }
                    } else {
                        splitUrl = res.result.path;
                    }
                    // let path=window.location.protocol+"//"+window.location.host+splitUrl;
                    let windowHost = window.location && window.location.protocol && window.location.host ? (window.location.protocol + '//' + window.location.host) : (window.location && window.location.origin ? window.location.origin : '');
                    // 判断是否是本地，如果是本地的话取https配置地址，线上则取地址栏地址 （内外网）
                    let httpUrl = windowHost && (windowHost.indexOf('localhost') !== -1 || windowHost.indexOf('127.0.0.1') !== -1) ? (httpConfig.ipDeault + splitUrl) : (window.location.protocol + '//' + window.location.host + splitUrl);
                    // let path=res.result.path
                    this.setState({
                        url: httpUrl + '?rpx=' + raqName + sessionStr,
                    })
                } else {
                    message.error("没数据");
                }
            }
        });
    }

    render() {
        return (
            <div style={{ height: '99%' }}>
                <iframe
                    style={{ width: '100%', border: '0px', height: '100%' }}
                    // sandbox="allow-scripts allow-forms allow-same-origin"
                    scrolling="auto"
                    src={this.state.url}
                />
            </div>
        );
    }
};
export default reports;
